home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / libfpvm / ftocstr.c next >
C/C++ Source or Header  |  1997-07-22  |  2KB  |  79 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: ftocstr.c,v 1.2 1997/07/09 13:30:14 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. #include "../src/bfunc.h"
  34.  
  35. #ifndef min
  36. #define min(i,j) ((i)<(j)?(i):(j))
  37. #endif
  38.  
  39.  
  40. ftocstr(ds, dl, ss, sl)
  41.     char *ds, *ss;      /* dst, src ptrs */
  42.     int dl;             /* dst max len */
  43.     int sl;             /* src len */
  44. {
  45.     char *p;
  46.  
  47.     for (p = ss + sl; --p >= ss && *p == ' '; ) ;
  48.     sl = p - ss + 1;
  49.     dl--;
  50.     ds[0] = 0;
  51.     if (sl > dl)
  52.         return 1;
  53.     strncat(ds, ss, min(sl, dl));
  54.     return 0;
  55. }
  56.  
  57.  
  58. ctofstr(ds, dl, ss)
  59.     char *ds;        /* dest space */
  60.     int dl;            /* max dest length */
  61.     char *ss;        /* src string (0-term) */
  62. {
  63.     int sl = strlen(ss);
  64.  
  65.     if (dl <= sl)
  66.         BCOPY(ss, ds, dl);
  67.  
  68.     else {
  69.         BCOPY(ss, ds, sl);
  70.         dl -= sl;
  71.         ds += sl;
  72.         while (dl-- > 0)
  73.             *ds++ = ' ';
  74.     }
  75.     return 0;
  76. }
  77.  
  78.  
  79.